﻿using System;
using System.Xml;

namespace CopyrightLib
{
    /// <summary>
    /// Класс настроек
    /// Сюда загружается настроечный xml
    /// </summary>
    public class MarkSettings
    {
        public VerticalAlignment VerticalAlignment { get; private set; }

        public HorizontalAlignment HorizontalAlignment { get; private set; }

        public Margin Margin { get; private set; }

        public double Angle { get; private set; }

        public int MarkType { get; private set; }

        public string Text { get; private set; }

        public MarkSettings(string settingsFilePath)
        {
            var doc = new XmlDocument();
            doc.Load(settingsFilePath);
            XmlElement root = doc.DocumentElement;
            foreach (XmlNode child in root.ChildNodes)
            {
                // избавимся так от комментов
                var elem = child as XmlElement;
                if (elem != null)
                {
                    switch (elem.Name)
                    {
                        case "MarkType":
                            MarkType = Convert.ToInt32(elem.InnerXml);
                            break;
                        case "Text":
                            Text = elem.InnerXml;
                            break;
                        case "VerticalAlignment":
                            VerticalAlignment = (VerticalAlignment)Convert.ToInt32(elem.InnerXml);
                            break;
                        case "HorizontalAlignment":
                            HorizontalAlignment = (HorizontalAlignment)Convert.ToInt32(elem.InnerXml);
                            break;
                        case "Angle":
                            Angle = Convert.ToDouble(elem.InnerXml);
                            break;
                        case "Margin":
                            int left = Convert.ToInt32(elem.GetAttribute("Left"));
                            int up = Convert.ToInt32(elem.GetAttribute("Up"));
                            int right = Convert.ToInt32(elem.GetAttribute("Right"));
                            int down = Convert.ToInt32(elem.GetAttribute("Down"));
                            Margin = new Margin(left, up, right, down);
                            break;
                        default:
                            continue;
                    }
                }
            }
        }
    }
}
